package com.foreveross.fetl.application.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.fetl.application.ICabinGradeApplication;
import com.foreveross.fetl.common.application.BaseApplicationImpl;
import com.foreveross.fetl.core.domain.cabin.CabinGradeEntity;
import com.foreveross.fetl.core.domain.cabin.CabinSubEntity;
import com.foreveross.fetl.vo.cabin.CabinGradeVO;
import com.foreveross.fetl.vo.cabin.CabinSubVO;
@Transactional
@Service("cabinGradeAppliction")
public class CabinGradeApplictionImpl extends BaseApplicationImpl implements
		ICabinGradeApplication {

	@Override
	public List<CabinGradeVO> listAll() {
		List<CabinGradeVO> results = new ArrayList<CabinGradeVO>();

		List<CabinGradeEntity> list = this.queryChannel2().queryResult("from CabinGradeEntity e", new Object[]{});
		CabinGradeVO vo = null;
		for(CabinGradeEntity e : list){
			vo = this.domain2Vo(e);
			for(CabinSubEntity se : e.getCabinSubs()){
				vo.getSubCabins().add(new CabinSubVO(se.getId(), se.getName(),se.getPriority()));
			}
			results.add(vo);
		}
		return results;
	}
	
	private CabinGradeVO domain2Vo(CabinGradeEntity entity){
		CabinGradeVO newVO = new CabinGradeVO();
		newVO.setId(entity.getId());
		newVO.setChannelId(entity.getChannel().getId());
		newVO.setChannelName(entity.getChannel().getName());
		newVO.setCode(entity.getCode());
		newVO.setCreateTime(entity.getCreateTime());
		newVO.setName(entity.getName());
		newVO.setUnifiedName(entity.getUnifiedName());
		newVO.setPriority(entity.getPriority());
		return newVO;
	}
	
}
